package com.parenting.controller;


import com.parenting.feign.controller.IFeignSystemAppletUserController;
import com.parenting.model.UserLowerDTO;
import com.parenting.oauth2.config.AuthUtil;
import com.parenting.response.RefuseRefundResponse;
import com.parenting.response.applet.ApprovalList;
import com.parenting.response.applet.RefundDetails;
import com.parenting.service.ExamineService;
import com.parenting.util.base.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 订单表  前端控制器
 * </p>
 *
 * @author 烟台业达-王世玺
 * @since 2021-09-18
 */
@RestController
@Api(tags = "审核通知", description = "退款退款 通知列表  退款详情")
@RequestMapping("/refund")
public class RefundReviewController {

    @Autowired
    private ExamineService examineService;

    @ApiOperation("待审批列表查询")
    @PostMapping("/pending/search")
    public Result<List<ApprovalList>> getPendingRefundList(){
        List<ApprovalList> approvalList = examineService.getApprovalList(AuthUtil.getUserInfo().getShopId());
        return Result.buildSuccess(approvalList);
    }


    @ApiOperation("已审批列表查询")
    @PostMapping("/already/search")
    public Result<List<ApprovalList>> getAlreadyRefundList(){
        List<ApprovalList> alreadyApprovalList = examineService.getAlreadyApprovalList(AuthUtil.getUserInfo().getShopId());
        return Result.buildSuccess(alreadyApprovalList);
    }

    @ApiOperation("同意退款")
    @GetMapping("/agree/{orderId}")
    public Result ByRefund(@PathVariable("orderId") String orderId){
        ;
        examineService.ByRefund(AuthUtil.getUserInfo(),orderId);
        return  Result.buildSuccess();
    }


    @ApiOperation("拒绝退款")
    @PostMapping("refuse")
    public Result RefuseRefund(@RequestBody  RefuseRefundResponse refuseRefundResponse){

        examineService.RefuseRefund(AuthUtil.getUserInfo(),refuseRefundResponse);
        return  Result.buildSuccess();
    }


    @Autowired
   private IFeignSystemAppletUserController feignSystemAppletUserController;

    @ApiOperation("店铺人员下拉")
    @PostMapping("lower")
    public  Result<List<UserLowerDTO>>   getUserLowerDtoByShopId(){
        List<UserLowerDTO> userLowerDtoByShopId = feignSystemAppletUserController.getUserLowerDtoByShopId(AuthUtil.getUserInfo().getShopId());
        return  Result.buildSuccess(userLowerDtoByShopId);
    }


    @ApiOperation("审核详情")
    @PostMapping("Approval/{orderId}")
    public  Result<RefundDetails> getRefundDetails(@PathVariable("orderId") String orderId){
        return Result.buildSuccess(examineService.refundDetails(orderId));
    }


//    @ApiOperation("查看审核通知订单详情")
//    @ApiImplicitParam(name = "orderId", value = "订单ID", required = true)
//    @GetMapping("{orderId}")
//    public Result<OrderDetailsResponse> getOrderDetailsById(@PathVariable("orderId") String orderId){
//        OrdersDO o = ordersService.getById(orderId);
//        OrderDetailsResponse orderDetailsResponse = BeanUtil.copyProperties(o, OrderDetailsResponse.class);
//
//        if (null==o.getOriginalPrice()){
//            o.setOriginalPrice(0);
//        }
//        if (null==o.getItemConcessional()){
//            o.setItemConcessional(0);
//        }
//        if (null==o.getItemNumber()){
//            o.setItemNumber(0);
//        }
//        Integer  discount=(o.getOriginalPrice()-o.getItemConcessional())*o.getItemNumber();
//        orderDetailsResponse.setDiscount(discount);
//        return Result.buildSuccess(orderDetailsResponse);
//    }
}
